rm(list = ls())

## packages 

library(tidyverse)
library(fixest)
library(lubridate)

## Load data 

dat <- readRDS('data/civey_clean.rds') 

## Table A.8

feols(vote_afd ~ treated_post | user_id + date, 
      data = dat,
      fsplit = ~ foreign_non_eu_share_bin, 
      cluster = ~ zip) %>%
  etable()

## Table A.9

feols(vote_afd ~ treated_post | user_id + date, 
      data = dat,
      fsplit = ~ foreign_non_eu_share_bin, 
      cluster = ~ county_id) %>%
  etable()

## Table A.11

feols(vote_afd ~ treated_post | user_id + date, 
      data = dat %>% filter(any_pool_in_zip == 1),
      fsplit = ~ foreign_non_eu_share_bin, 
      cluster = ~ user_id) %>%
  etable()

## Table A.12

feols(vote_afd ~ treated_post | user_id + date, 
      data = dat %>% filter(!(any_pool_in_zip == 1 & freibad_in_zip == 0)),
      fsplit = ~ foreign_non_eu_share_bin, 
      cluster = ~ user_id)  %>%
  etable()


## Table A.13

feols(vote_afd ~ treated_post | user_id + date, 
      data = dat %>% mutate(s_year = year(date)) %>% filter(foreign_non_eu_share_bin == 'High'),
      fsplit = ~ s_year, 
      cluster = ~ user_id) %>%
  etable()


